<template>
  <div>
    <h1>消息通知 (⁎⁍̴̛ᴗ⁍̴̛⁎)</h1><hr>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          prop="dbSysCrop.cropNumbering"
          label="货物编号"
          width="180">
      </el-table-column>
      <el-table-column
          prop="dbSysCrop.cropName"
          label="货物名称"
          width="120">
      </el-table-column>
      <el-table-column
          prop="cropAddr"
          label="发货地址"
          width="120">
      </el-table-column>
      <el-table-column
          prop="sysManufacturer.addr"
          label="送货地址"
          width="120">
      </el-table-column>
      <el-table-column
          prop="remark"
          label="备注"
          width="120">
      </el-table-column>
      <el-table-column
          label="操作"
          width="140">
        <template slot-scope="scope">
          <el-button v-if="scope.row.dbSysCrop.sysTypeState==4" @click="takeOrders(scope.row)" type="text" size="small">接单</el-button>
          <el-button v-if="scope.row.dbSysCrop.sysTypeState==3" type="text" @click="orderFulfillment(scope.row)" size="small">订单完成</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "MessageView",
  data(){
    return{
      tableData:[]
    }
  },methods:{
    /*该司机接收到的订单信息*/
    list(){
      let userId = localStorage.getItem("userId");
      this.axios.post("http://172.20.10.5:8003/api/sys-crop/messageList?userId="+userId).then(res=>{
        if(res.data=="error"){
          this.$message.error("暂无通知")
        }
        this.tableData=res.data
        console.log("信息通知为：===="+JSON.stringify(res.data))
      })
    },takeOrders(row){
      //alert(row.dbSysCrop.cropNumbering)
      this.axios.post("http://172.20.10.5:8003/api/sys-crop/takeOrders?logisticsNumber="+row.dbSysCrop.cropNumbering+"&cropId="+row.cropId).then(res=>{
        if(res.data=="success"){
          this.$message.success("接单成功");
          this.list();
        }else{
          this.$message.error("接单失败")
        }
      })
    },/*订单完成*/
    orderFulfillment(row){
      this.axios.post("http://172.20.10.5:8003/api/sys-crop/orderFulfillment?logisticsNumber="+row.dbSysCrop.cropNumbering+"&cropId="+row.cropId).then(res=>{
        if(res.data=="success"){
          this.$message.success("订单完成")
          this.list();
        }else{
          this.$message.error("订单完成失败")
        }
      })
    }
  },created() {
    this.list()
  }
}
</script>

<style scoped>

</style>